<template>
  <div>
    <headerNav />
    <div class="mincard">
      <div class="mindWidth fontSize">
        <span @click="$router.push('/')">首页</span> >
        <span @click="toRoute">最新资讯</span> >
        <span>详情</span>
      </div>
    </div>
    <div class="informList">
      <div class="mindWidth navOBJ">
        <div class="navContainer navlist">
          <div class="conetent_inform">
            <div class="title">
              <h4>{{ DetailsList.title }}</h4>
            </div>
            <div class="from_content">
              <div class="from_t flex items-middle space-between">
                <div>
                  <span>日期: {{ DetailsList.createTime }}</span>
                  <span>
                    来源:
                    <em>{{ DetailsList.nickName }}</em>
                  </span>
                </div>
                <div>
                  <!-- <span v-if="DetailsList.whetherCanExport===1" class="export" @click="exportName">符合申报条件企业名单</span> -->
                  <el-tooltip
                    v-if="DetailsList.whetherCanExport===1"
                    class="item"
                    effect="dark"
                    content="下载"
                    placement="top"
                  >
                    <el-button
                      class="export"
                      @click="exportName"
                    >{{ downName === 1 ? '符合申报条件企业名单' : '符合下一批申报企业名单' }}</el-button>
                  </el-tooltip>
                </div>
              </div>
            </div>
            <div class="conetent" v-html="DetailsList.content"></div>
            <div class="from_b">
              <a v-if="linkSf" :href="DetailsList.link" target="_blank">阅读原文</a>
              <span>阅读量</span>
              {{ DetailsList.pageViewCount }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 订阅已满 -->
    <el-dialog
      :visible.sync="dialogVisible"
      :show-close="false"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      width="300px"
    >
      <template #footer>
        <div class="contents_qydb">
          <img src="../../static/image/cwhyts2.png" alt class="imgs_qydb" />
          <div class="goVip">
            <div class="top">可下载数量已满</div>
            <div class="bn">成为VIP会员畅享更多权益</div>
          </div>
          <div class="option">
            <span class="spans_qydb" @click="dialogVisible = false">再用看看</span>
            <p class="ps_qydb" @click="toVipPage">升级VIP</p>
          </div>
        </div>
      </template>
    </el-dialog>
    <navigation></navigation>
    <footerNav />
    <!-- 登录弹窗 -->
    <login-dialog ref="login" @reload="reload"></login-dialog>
  </div>
</template>

<script>
import shareCard from "../../components/shareCard/index.vue";
import { mapMutations } from "vuex";
import { sessionTake } from "../../util/validate";
import {
  noticeDownloadExcel,
  whetherCanExport,
  whetherDownload
} from "../../api/api.js";
import loginDialog from "../../components/login_item/LoginDialog";
import {
  commonRequest,
  commonRequestSsr,
  postRequestSplicing,
  postRequest,
  getNewsDetail,
  getNewsDetailSsr
} from "../../api/api.js";

export default {
  name: "newInform",
  components: {
    shareCard,
    loginDialog
  },
  head() {
    return {
      title: `${this.DetailsList.title}-比目镜`,
      meta: [
        { hid: "keywords", name: "keywords", content: this.DetailsList.title },
        {
          hid: "description",
          name: "description",
          content: this.DetailsList.title
        }
      ]
    };
  },
  data() {
    return {
      dialogVisible: false, // 订阅已满
      DetailsList: "", // 详情数据列表
      lookingData: [],
      linkSf: false,
      policyId: this.$route.query.id,
      downName: 1 // 下载名单 2公示：下一批符合条件可申报企业名单 1通知：符合申报条件企业名单
    };
  },
  watch: {
    $route(to, from) {
      if (to.name == "newInform") {
        this.$router.go(0);
      }
    }
  },
  async asyncData({ app, route, err }) {
    let id = route.params.id;
    let res;
    // if (process.server) {
    //   res = await getNesDetailSsr(id);
    // } else {
    res = await getNewsDetail(id);
    // }
    let downName = 1;
    if (res.result.title.includes("公示")) {
      downName = 2;
    } else {
      downName = 1;
    }
    return {
      DetailsList: res.result,
      downName: downName
    };
  },
  mounted() {
    // this.getArticleDetails();
  },
  methods: {
    // 登录刷新当前页
    reload() {
      location.reload();
    },
    toVipPage() {
      window.open("/pageVIP", "_blank");
    },
    // 获取详情列表
    getArticleDetails() {
      let { id } = this.$route.params;
      commonRequest(`/api/pms/pmsLatestNews/detail/${id}`).then(res => {
        this.DetailsList = res;
        // 判断标题关键字
        if (this.DetailsList.title.includes("公示")) {
          this.downName = 2;
        } else {
          this.downName = 1;
        }
      });
    },
    canExport() {
      whetherCanExport().then(res => {
        if (res.code === 10001) {
          this.$refs.login.open();
        } else if (res.code === 10006) {
          this.dialogVisible = true;
        } else if (res.code === 200) {
          whetherDownload({ source: "0", policyId: this.policyId });
          noticeDownloadExcel({ policyId: this.policyId }).then(res => {
            let blob = new Blob([res.data]);
            let link = document.createElement("a");
            let fileName = "可申报企业名单.xls";
            link.href = window.URL.createObjectURL(blob);
            link.download = decodeURIComponent(fileName);
            link.click();
          });
        }
      });
    },
    // 下载名单
    exportName() {
      // whetherDownload({source: '0'})
      this.canExport();
    },
    toRoute() {
      let params = { province: "", city: "" };
      let provinceName = sessionTake("provinceName");
      let cityName = sessionTake("cityName");
      if (provinceName && cityName) {
        params.province = provinceName;
        params.city = cityName;
        this.$router.push({
          name: "newsInfomation",
          params: params
        });
      } else {
        this.$router.push({
          name: "newsInfomation"
        });
      }
    }
  }
};
</script>
<style>
.informList a {
  color: blue;
}
</style>
<style lang="less" scoped>
/deep/ .el-button {
  border: none;
}

/* 弹框的开始 */
:deep(.el-dialog__footer) {
  height: 310px;
}

.contents_qydb {
  width: 200px;
  margin-left: 22px;
  margin-top: 20px;

  .goVip {
    display: flex;
    flex-direction: column;
    position: absolute;
    bottom: 55px;
    align-items: center;
    justify-content: center;
    width: 100%;
    left: 0;

    .top {
      font-size: 14px;
      color: #000;
    }

    .bn {
      font-size: 14px;
      color: #1d78de;
    }
  }
}

.el-dialog__footer {
  height: 340px;
  position: relative;
}

.option {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 40px;
  bottom: 10px;
  width: 100%;
  font-size: 14px;
  left: 0;

  .spans_qydb {
    background-color: #bfbfbf;
    padding: 4px 30px;
    color: #fff;
    cursor: pointer;
    border-radius: 30px;
  }

  .ps_qydb {
    border-radius: 30px;

    background-color: #1d78de;
    padding: 4px 30px;
    color: #fff;
    cursor: pointer;
    // bottom: 15px;
    // right: 26px;
    // width: 159px;
    // height: 44px;
    // cursor: pointer;
  }
}

.el-dialog {
  border-radius: 10px;
}

.imgs_qydb {
  width: 100%;
  border-radius: 10px;
}

.navlist {
  margin: 10px 0;
}

.fontSize {
  span {
    font-size: 14px;
    margin: auto 2px;
    cursor: pointer;
  }
}

.navOBJ {
  // display: flex;
  // justify-content: space-around;
}

.informList {
  background-color: #fff;
}

.navContainer {
  width: 100%;
  // overflow: auto;
}

.from_b {
  display: flex;
  align-items: center;
  font-size: 14px;
  margin-bottom: 30px;

  a {
    color: rgb(68, 162, 255);
    margin-right: 20px;
    font-size: 14px;
  }

  .share {
    display: flex;
    align-items: center;
    font-size: 14px;
    cursor: pointer;
  }

  img {
    width: 18px;
    height: 15px;
    margin: 0 10px;
  }

  span {
    font-size: 14px;
    margin-right: 10px;
  }
}

.conetent_inform {
  width: 100%;
  border-bottom: 1px solid #ccc;
  min-height: 400px;

  .title {
    h4 {
      font-size: 28px;
    }
  }

  .from_content {
    margin: 30px 0 40px 0;
    color: #999;

    .from_t {
      height: 30px;
      line-height: 30px;

      span {
        font-size: 14px;
        margin-right: 10px;

        em {
          font-style: normal;
          cursor: pointer;
          transition: all 0.2s;

          &:hover {
            color: rgb(68, 162, 255);
          }
        }
      }

      .button1 {
        color: #44a2ff;
        background-color: #fff;
        border-radius: 2px;
        border: 1px solid #44a2ff;
        cursor: pointer;
      }

      .on-btn {
        margin-left: 10px;
        color: rgb(68, 162, 255);
        cursor: pointer;
      }

      .export {
        font-weight: 600;
        font-size: 18px;
        color: red;
        cursor: pointer;
      }

      .button2 {
        background-color: rgb(203, 220, 232);
        border-color: rgb(203, 220, 232);
        color: #fff;
      }
    }
  }

  .conetent {
    margin-bottom: 40px;
    font-size: 16px;
  }
}

.nextinform_content {
  width: 840px;
  overflow: hidden;
  padding: 10px 0;

  .per_from,
  .next_from {
    width: 410px;
    float: left;
    margin-right: 10px;

    span {
      color: #44a2ff;
      font-size: 14px;
    }

    p {
      font-size: 14px;
      cursor: pointer;

      &:hover {
        color: #44a2ff;
      }
    }
  }
}

.observe {
  // margin-left: 60px;
  display: flex;
  width: 327px;

  .img_border {
    width: 100%;
    // margin: 20px auto;
    margin-right: 40px;

    img {
      width: 300px;
      height: 250px;
    }
  }

  .reader {
    .title {
      font-size: 20px;
    }

    .reader_content {
      margin-top: 15px;
      width: 327px;
      height: 267px;
      border: 1px #000 transparent;
      padding: 20px 5px;

      .readee_order {
        border-bottom: 1px rgba(243, 243, 243, 0.5) solid;
        height: 50px;
        line-height: 50px;
        font-size: 14px;
        cursor: pointer;

        &:hover {
          color: #44a2ff;
        }

        i {
          display: inline-block;
          border: 2px solid #000;
          width: 8px;
          height: 8px;
          margin: 0 10px;
        }
      }
    }
  }
}
</style>
